package Job02;

import java.text.Collator;
import java.util.*;

public class CustomerBiz {
    private final static Comparator<Object> CHINA_COMPARE = Collator.getInstance(Locale.CHINA);
    public String[] names = new String[10];

    public void addName(String name){
        for (int i = 0; i < names.length; i++) {
            if (names[i] == null){
                names[i] = name;
                break;
            }
        }
    }

    public void updateName(String oldName,String newName){
        int Index = sortNames(oldName);
        if (Index != -1){
            names[Index] = newName;
        }else {
            System.out.println("没找着此学生");
        }
    }

    public int sortNames(String name){
        List<String> ciy = new ArrayList<String>();
        for (int i = 0; i < names.length; i++) {
            if (name.equals(names[i])){
                return i;
            }
        }
        Collections.sort(ciy,CHINA_COMPARE);
        return -1;
    }

    public String[] searchName(int sta,int end,String name){
        String[] res = new String[0];
        int k = 0;
        for (int Idx = sta - 1; Idx < end; Idx++) {
            if (names[Idx].contains(name)){
                res = Arrays.copyOf(res,res.length+1);
                res[k++] = names[Idx];
            }
        }
        return res;
    }

    public void deleteName(String name){
        int Index = sortNames(name);
        if (Index != -1){
            for (int i = Index; i < names.length -1; i++) {
                names[i] = names[i+1];
            }
            names[names.length - 1] = null;
        }else {
            System.out.println("没有找到要删除的学生");
        }
    }

    public void show01(){
        for (int i = 0; i < names.length; i++) {
            System.out.print(names[i]+ " ");
        }
    }

}
